package top.zackyoung.redis.on;

import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer;
import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author ZackYoung
 * @version 1.0
 * @date 2021/11/5
 */
@Service
public class TestServiceImpl implements TestService {
    @Resource
    CacheManager cacheManager;
    @Override
    @Cacheable(value = "test", key = "#id.toString()",  unless = "#result.get('id')!=1001")
    public Map<String, Object> map(Integer id) {
        return new HashMap<>() {{
            put("id",id);
            put("xx", "1");
            put("y", 1);
            put("z", Stream.of(1, 2, 3).toArray());
            put("a", new HashMap<String, String>() {{
                put("k", "v");
            }});
        }};
    }
}
